﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data.OracleClient;

namespace CeA.Reports.Atendimento.DataAccess.Helpers {
    public class OracleParameterHelper {

        public static string BuildInClauseFor(OracleCommand command, string parameterName, List<int> list) {
            StringBuilder sb = new StringBuilder();
            String paramString = string.Empty;

            if (list.Count == 1) {
                sb.AppendFormat("= {0}", parameterName);
                command.Parameters.AddWithValue(parameterName, list[0]);
            }
            else {
                sb.AppendFormat("in ( ");
                for (int i = 0; i < list.Count; i++) {
                    sb.AppendFormat("{0}{1}", parameterName, i);
                    if (i < list.Count - 1)
                        sb.AppendFormat(", ");

                    paramString = string.Format("{0}{1}", parameterName, i);
                    command.Parameters.AddWithValue(paramString, list[i]);
                }
                sb.AppendFormat(" )");
            }

            return sb.ToString();
        }

        public static string BuildInClauseFor(OracleCommand command, string parameterName, List<string> list) {
            StringBuilder sb = new StringBuilder();
            String paramString = string.Empty;

            if (list.Count == 1) {
                sb.AppendFormat("= {0}", parameterName);
                command.Parameters.AddWithValue(parameterName, list[0]);
            }
            else {
                sb.AppendFormat("in ( ");
                for (int i = 0; i < list.Count; i++) {
                    sb.AppendFormat("{0}{1}", parameterName, i);
                    if (i < list.Count - 1)
                        sb.AppendFormat(", ");

                    paramString = string.Format("{0}{1}", parameterName, i);
                    command.Parameters.AddWithValue(paramString, list[i]);
                }
                sb.AppendFormat(" )");
            }

            return sb.ToString();
        }
    }
}
